# Contributor: Stuart Cardall <developer@it-offshore.co.uk>
# Maintainer: Stuart Cardall <developer@it-offshore.co.uk>
pkgname=criu
pkgver=3.19
pkgrel=1
pkgdesc="Process tree checkpoint/restore utility"
url="https://criu.org"
arch="x86_64"
license="GPL-2.0-or-later LGPL-2.1-only"
makedepends="
	asciidoc
	libaio-dev
	libcap-dev
	libnet-dev
	libnl3-dev
	nftables-dev
	protobuf-c-dev
	protobuf-dev
	py3-gpep517
	py3-protobuf
	py3-setuptools
	py3-wheel
	python3
	xmlto
	"
checkdepends="py3-yaml"
options="!check" # https://github.com/checkpoint-restore/criu/issues/434
subpackages="$pkgname-dev $pkgname-doc py3-$pkgname-pyc py3-$pkgname:_py:noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/checkpoint-restore/criu/archive/v$pkgver.tar.gz
	lfs64.patch
	lfs64-test.patch
	"

build() {
	make \
		CONFIG_AMDGPU=n \
		PREFIX=/usr \
		DESTDIR="$pkgdir" \
		LIBDIR=/usr/lib \
		LD="${CC:-gcc}"
	cd crit
	CRIU_VERSION_MAJOR="${pkgver%%.*}" \
	CRIU_VERSION_MINOR="${pkgver##*.}" \
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
	cd ../lib
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	make test
}

package() {
	make \
		CONFIG_AMDGPU=n \
		PREFIX=/usr \
		DESTDIR="$pkgdir" \
		LIBDIR=/usr/lib \
		LD="${CC:-gcc}" install
	rm "$pkgdir"/usr/libexec/criu/scripts/systemd-autofs-restart.sh
	rm -f "$pkgdir"/usr/lib/*.a
	python3 -m installer -d "$pkgdir" \
		crit/.dist/*.whl
	python3 -m installer -d "$pkgdir" \
		lib/.dist/*.whl
}

_py() {
	replaces="py-$pkgname" # Backwards compatibility
	provides="py-$pkgname=$pkgver-r$pkgrel" # Backwarwds compatibility

	pkgdesc="Python3 bindings for Criu"
	depends="python3 py3-protobuf"
	amove usr/lib/python*
}

sha512sums="
d243818cdac51580c952a80e9164786a67ce5e294c0faa6dc700f5e8da8e36495f0b64f5c27b345ede7d6697ed7a69fa4e9a85cef451f32e3ffeb78564884571  criu-3.19.tar.gz
d8906903972ec92667c60b6a9b8b1ca360a657556afcd62f851af0e98e904c1b58899377dfba475599f46e4b825ebf6edfe844b839149e47983084a0f55b0352  lfs64.patch
f89267453dc089125d29f696635d798602658b5deeda83d1de0ae5959eea60804f3e26dd024520d12fed104692a65f11c3d1e0db819e7e87dda450120981afd8  lfs64-test.patch
"
